package com.yeyks.controller.admin;

import com.yeyks.common.appcommon.dto.AppAddressDTO;
import com.yeyks.common.appcommon.param.QueryAddressParam;
import com.yeyks.common.appcommon.result.CommonResult;
import com.yeyks.commonReference.service.account.AccountInfoService;
import com.yeyks.controller.BaseController;
import com.yeyks.other.service.AddressDivisionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * @author: gui
 * @date: 2019/5/20 0020 15:45
 */
@Api(tags = "AppCommonAddressController_公共地址接口", description = "公共地址相关接口信息")
@RestController
@RequestMapping("/admin/address")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AppCommonAddressController extends BaseController {

    private final AccountInfoService accountInfoService;

    private final AddressDivisionService addressDivisionService;

    @PostMapping("/query")
    @ApiOperation("地址下拉搜索")
    public CommonResult<List<AppAddressDTO>> getAddressByCode(@Valid QueryAddressParam addressParam){


        return addressDivisionService.getAddressByCode(addressParam);
        //return addressService.getAddressByCode(addressParam);
    }

    @PostMapping("/update/account/code")
    @ApiOperation("全量更新没有省、市、区/县 的code值---> 可以重复调用")
    public CommonResult updateAccountCode(
            @ApiParam(name = "status", value = "是否全量更新， 1:只查没有code的数据更新， 2: 查询所有的进行更新", required = true,
                    allowableValues = "1,2")
            @RequestParam(value = "status", defaultValue = "1")Integer status){

        return accountInfoService.updateAccountCode(status);
    }

    @PostMapping("/update/address/data")
    @ApiOperation("更新拉取所有地址数据进行更新, 【注意】前提， 先删除之前的数据")
    public CommonResult updateOrAddAllAddress() throws IOException {

        return addressDivisionService.updateOrAddAllAddress();
        //return addressService.updateOrAddAllAddress();
    }

    @PostMapping("/add/other/address")
    @ApiOperation("循环加入每个市的 其它区 , 其它区的规则 ： 00 (省) 00(市) 99(区/县) ---> 可以重复调用")
    public CommonResult addOtherCountryAddress(){

        return addressDivisionService.updateAllOtherCountry();
        //return addressService.updateAllOtherCountry();
    }

}
